import 'package:extended_image/extended_image.dart';
import 'package:flutter/material.dart';

class BarrageTwo extends StatefulWidget {
  final String? avatar;
  final String name;
  final String operation;
  final String result;

  BarrageTwo({
    this.avatar,
    required this.name,
    required this.operation,
    required this.result,
  });

  @override
  _BarrageTwoState createState() => _BarrageTwoState();
}

class _BarrageTwoState extends State<BarrageTwo> {
  final double _size = 36;
  final BorderRadius _borderRadius = BorderRadius.circular(30);

  @override
  Widget build(BuildContext context) {
    return DefaultTextStyle(
      style: TextStyle(
        color: Colors.white,
        fontSize: 14,
        height: 1,
      ),
      child: Stack(
        children: [
          // 内容
          Container(
            height: _size - 6,
            margin: EdgeInsets.symmetric(vertical: 3),
            padding: EdgeInsets.only(left: 40, right: 20),
            decoration: BoxDecoration(
              color: Color.fromRGBO(0, 0, 0, 0.4),
              borderRadius: _borderRadius,
            ),
            child: Row(
              crossAxisAlignment: CrossAxisAlignment.center,
              children: [
                // 名称
                Container(
                  constraints: BoxConstraints(
                    maxWidth: 80,
                  ),
                  child: Text(
                    widget.name,
                    maxLines: 1,
                    overflow: TextOverflow.ellipsis,
                    style: TextStyle(
                      fontWeight: FontWeight.bold,
                    ),
                  ),
                ),
                SizedBox(width: 5),
                // 操作
                Text(widget.operation),
                SizedBox(width: 5),
                // 结果
                Container(
                  constraints: BoxConstraints(
                    maxWidth: 80,
                  ),
                  child: Text(
                    widget.result,
                    maxLines: 1,
                    overflow: TextOverflow.ellipsis,
                    style: TextStyle(
                      color: Color.fromRGBO(239, 237, 77, 1),
                    ),
                  ),
                ),
              ],
            ),
          ),
          ClipRRect(
            borderRadius: BorderRadius.circular(_size),
            child: ExtendedImage.network(
              widget.avatar!,
              width: _size,
              height: _size,
              fit: BoxFit.cover,
            ),
          ),
        ],
      ),
    );
  }
}
